const CONFIG = require('../../config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    h5url: 'https://wx.huidailang.cn',
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#39a9ed))',
    formData: {},
    rules: [],
    payMoney: [
      {
          money: 5,
          num: 50,
      },
      {
          money: 10,
          num: 100,
      },
      {
          money: 20,
          num: 200,
      },
      {
          money: 30,
          num: 300,
      },
      {
          money: 50,
          num: 500,
      },
      {
          money: 100,
          num: 1000,
      },
    ],
    score: 50,
    amount: 5,
    idx: 0
  },

  changeTap(e){
    const data = e.currentTarget.dataset;
    this.setData({
      amount: data.score.money,
      score: data.score.num,
      idx: data.index
    })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  formInputChange(e){
    const {field} = e.currentTarget.dataset;
    this.setData({
      amount: e.detail.value,
      score: e.detail.value * 10
    })
  },

  saveMoney(){
    let params = {
      amount:this.data.amount
    };
    let loginInfo = wx.getStorageSync('loginInfo');
    if(loginInfo){
      loginInfo = JSON.parse(loginInfo);
    }
    params.openid = loginInfo.openid;
    wx.request({
      url: CONFIG.host + "/system/weiXinPayController/payOrder",
      data: params,
      method: "GET",
      header: {
        'content-type': 'application/json',
			  'Authorization': loginInfo.token
      },
      success: res => {
        if(res.data.code === 'success'){
          let data = res.data.data;
          wx.requestPayment(
            {
            'timeStamp': data.timeStamp,
            'nonceStr': data.nonceStr,
            'package': data.package,
            'signType': 'MD5',
            'paySign': data.paySign,
            'success':function(res){
              console.log('success')
            },
            'fail':function(res){
              console.log('fail', res)
            },
            'complete':function(res){
              console.log('complete',res)
            }
            })
        }
      },fail: function (error) {
        console.log(error);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})